<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>售后申请</title>

    <link href="../../resource/css/bootstrap.min.css?v=3.3.5" rel="stylesheet"
          th:href="@{/resource/css/bootstrap.min.css?v=3.3.5}"/>
    <link href="../../resource/hotui/css/font-awesome.min.css" th:href="@{/resource/hotui/css/font-awesome.min.css}"
          rel="stylesheet">
    <!-- Morris -->
    <link href="../../resource/hotui/css/plugins/morris/morris-0.4.3.min.css"
          th:href="@{/resource/hotui/css/plugins/morris/morris-0.4.3.min.css}" rel="stylesheet">
    <link href="../../resource/hotui/css/style.min-1.0.8.css" th:href="@{/resource/hotui/css/style.min-1.0.8.css}"
          rel="stylesheet">
    <link href="../../resource/hotui/css/hotui.style.override.css"
          th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>

</head>

<body th:object="${bill}">
<form id="saveForm">
    <div class="wrapper wrapper-content tooltip-demo" style="max-height: 492px; overflow-y: auto;">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins" style="margin-bottom: 0;">
                    <div class="ibox-title" style="padding: 0; min-height: initial;">
                        <div class="form-inline">
                            <div class="form-group m-r-sm">
                                <input type="hidden" th:value="*{id}" id="id"/>
                                <label style="font-size: 17px;">售后单号：<span
                                        th:text="*{id}">20170110893091324683</span></label>
                                &nbsp;
                                <span th:text="*{afterSaleStatus.desc}">售后申请中</span>
                            </div>
                            <div class="form-group m-r-sm" style="float: right;">
                                <label style="font-size: 14px; font-weight: normal;">
                                    <span class="glyphicon glyphicon-time"></span>
                                    <span th:text="*{#temporals.format(createTime,'yyyy-MM-dd HH:mm:ss')}">2017/1/10 21:08:44</span></label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <p style="height: 20px"></p>
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins m-b-none">
                    <div class="ibox-content p-xxs no-borders" style="border-top: none;">
                        <table class="table table-bordered">
                            <tbody>
                            <tr>
                                <th>售后单号：</th>
                                <td class="form-inline" th:text="*{id}">20170110893091324683</td>
                                <th>订单号：</th>
                                <td th:text="*{subOrderId}">20170110893091324683</td>
                            </tr>
                            <tr>
                                <th>商品：</th>
                                <td class="form-inline" th:text="*{goodsInfo.goodsName}">123</td>
                                <th:block sec:authorize="hasRole('ADMIN')">
                                    <th>用户：</th>
                                    <td th:text="*{userPO.nickName}"></td>
                                </th:block>
                            </tr>
                            <tr>
                                <th>售后类型：</th>
                                <td class="form-inline" th:text="*{afterSaleType.desc}">退款并退货</td>
                                <th>售后原因：</th>
                                <td class="form-inline" th:text="*{reason}">123</td>
                            </tr>
                            <tr>
                                <th>应退金额：</th>
                                <td class="form-inline">
                                    <span th:text="*{totalAmount}"></span>
                                    <input type="hidden" id="hdTotalAmount" th:value="*{totalAmount}"/>
                                </td>
                                <th:block sec:authorize="hasRole('ADMIN')">
                                    <th>实退金额：</th>
                                    <td>
                                        <th:block th:if="*{finalAmount!=null}">
                                            ￥<span th:text="*{finalAmount}">100</span>
                                            （余额：￥<span th:text="*{refundBalance}">50</span>）
                                        </th:block>
                                    </td>
                                </th:block>
                            </tr>
                            <th:block sec:authorize="hasRole('ADMIN')">
                                <tr>
                                    <th>扣除一级佣金：</th>
                                    <td class="form-inline">
                                        ￥<span th:text="*{fatherRebate}"></span>
                                    </td>
                                    <th>扣除二级佣金：</th>
                                    <td>
                                        ￥<span th:text="*{grandRebate}">100</span>
                                    </td>
                                </tr>
                                <tr>
                                    <th>扣除货款：</th>
                                    <td class="form-inline">
                                        ￥<span th:text="*{payment}"></span>
                                    </td>
                                </tr>
                            </th:block>

                            <tr>
                                <th>用户留言：</th>
                                <td colspan="3">
                                    <textarea th:value="*{userMemo}" placeholder="用户留言" name="userMemo" id="userMemo"
                                              class="form-control"
                                              rows="5" style="height: 56px;"></textarea>
                                </td>
                            </tr>
                            <tr>
                                <th>图片：</th>
                                <td colspan="3">
                                    <img th:each="image:*{images()}" th:src="${@resourceService.get(image).getURI()}"
                                         style="width: 128px;height: 128px;" src="../../resource/img/profile.jpg"/>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row" style="padding: 0 15px; position: absolute; bottom: 0; width: 100%;">
        <div class="col-lg-12">
            <div class="ibox float-e-margins" style="margin-bottom: 0;">
                <div class="ibox-title" style="padding: 0; min-height: initial;">
                    <div class="form-group " style="float: right;">
                        <th:block th:if="*{afterSaleStatus.code==1}">
                            <button type="button" id="approve" onclick="asHandler.approve()" class="btn btn-primary">
                                同意申请
                            </button>
                            <button type="button" id="refuse" onclick="asHandler.refuse()" class="btn btn-danger">拒绝申请
                            </button>
                        </th:block>
                        <button th:if="*{enableRefund()}" type="button" id="refund" onclick="asHandler.refund()"
                                class="btn btn-primary">退款
                        </button>
                        <button type="button" class="btn btn-white m-l" onclick="javascript:parent.layer.close(index);">
                            关闭
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<script src="../../resource/js/jquery.min.js?v=2.1.4" th:src="@{/resource/js/jquery.min.js?v=2.1.4}"></script>
<script src="../../resource/js/bootstrap.min.js?v=3.3.5" th:src="@{/resource/js/bootstrap.min.js?v=3.3.5}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js(123123)}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js"></script>
<script src="../../resource/hotui/js/content.min.js" th:src="@{/resource/hotui/js/content.min.js}"></script>

<script type="text/javascript" th:inline="javascript">
    const apiUri = /*[[@{/order/afterSale}]]*/ "";
</script>

<script type="text/javascript">
    var index = parent.layer.getFrameIndex(window.name);

    var asHandler = {
        approve: function () {
            hot.confirm("确定同意售后？", function () {
                hot.ajax(apiUri + "/approve", {
                    id: $("#id").val()
                }, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        hot.tip.success("操作成功", function () {
                            parent.location.reload();
                            parent.layer.close(index);
                        });
                    } else {
                        hot.tip.error(apiResult.resultMsg);
                    }
                }, function () {
                }, "post", 300);
            });
        },
        refuse: function () {
            layer.prompt({title: '拒绝售后', formType: 2}, function (text, index) {
                hot.ajax(apiUri + "/refuse", {
                    id: $("#id").val(),
                    remark: text
                }, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        hot.tip.success("操作成功", function () {
                            parent.location.reload();
                            parent.layer.close(index);
                        });
                    } else {
                        hot.tip.error(apiResult.resultMsg);
                    }
                }, function () {
                }, "post", 300);
            });
        },
        refund: function () {
            hot.confirm("确定退款，退款金额：" + $("#hdTotalAmount").val(), function () {
                hot.ajax(apiUri + "/refund", {
                    id: $("#id").val(),
                }, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        hot.tip.success("操作成功", function () {
                            parent.location.reload();
                            parent.layer.close(index);
                        });
                    } else {
                        hot.tip.error(apiResult.resultMsg);
                    }
                }, function () {
                }, "post", 300);
            });
        }
    }
</script>
</body>

</html>
